<script type="text/javascript" src="{:U(MODULE_NAME. '/Public/editor')}"></script>
<script type="text/javascript" src="/Public/js/jquery.form.min.js"></script>

<style type="text/css">
  .ly-addbox{margin: 0 auto;padding: 10px;font-size: 14px;}
  .ly-addbox .label-180{ display: block; float: left; width: 180px; text-align: right;}
</style>

<div class="main_top">
  <a href ="{:U(MODULE_NAME.'/Product/customEdit', array('id'=>$id))}" class=" <if condition='$step eq 0'>bg_blue<else/></if>">主要信息</a>
  <a href ="{:U(MODULE_NAME.'/Product/customEdit', array('id'=>$id,'step'=>1))}" class=" <if condition='$step eq 1'>bg_blue</if>">费用包括</a>
  <a href ="{:U(MODULE_NAME.'/Product/customEdit', array('id'=>$id,'step'=>2))}" class=" <if condition='$step eq 2'>bg_blue</if>">费用不含</a>
  <a href ="{:U(MODULE_NAME.'/Product/customEdit', array('id'=>$id,'step'=>3))}" class=" <if condition='$step eq 3'>bg_blue</if>">预定须知</a>
  <a href ="{:U(MODULE_NAME.'/Product/customEdit', array('id'=>$id,'step'=>4))}" class=" <if condition='$step eq 4'>bg_blue</if>">退订须知</a>
  <a href ="javascript:window.open('http://192.168.1.219{:U(MODULE_NAME.'/Departure/indexsell',array('pid'=>$id))}')" >出发日期</a>
  <a href ="javascript:window.open('http://192.168.1.219{:U(MODULE_NAME.'/HotelManage/indexsell',array('pid'=>$id))}')">酒店信息</a>
</div>
<div class="form">
  <form method='post' id="form_do" name="form_do" action="{:U(MODULE_NAME.'/Product/customAdd',array('step'=>$step))}">

    <if condition="$step eq false">
    <dl>
      <dt>产品库产品：</dt>
        <dd>
          <div class="operateDeparture">
            <input type="text" class="inp_small" name="libraryProductID" onkeyup="getLibrary(this)" value="{$product.libraryProductID}"  >&nbsp;&nbsp;
            <input type="text" class="inp_default" name="libraryTitle" value="{$product.title}" >&nbsp;&nbsp;
            <span id="departureCitySow" ></span>&nbsp;&nbsp;
            <select name="addPriceType" onchange="changePriceType()" >
              <option value="0" <if condition="$product['gainType'] eq '0'">selected</if> >成本价</option>
              <option value="1" <if condition="$product['gainType'] eq '1'">selected</if> >手动输入加价额度</option>
              <option value="2" <if condition="$product['gainType'] eq '2'">selected</if> >按成本百分比加价%</option>
            </select>
            &nbsp;&nbsp;
            <input type="text" name="addPriceNums" onkeyup="changePriceType()" style="width:50px;" <if condition="$product['gainType'] eq '0'">disabled="disabled"</if>  value="{$product.gainNums}"> &nbsp;&nbsp;
            <font class="font-green"><span id="priceShow">{$product.sellPrice}</span>元</font> &nbsp;&nbsp;
          </div>
        </dd>
    </dl>
    <dl>
      <dt> 现价：</dt>
      <dd>
        <input type="text" name="price" class="inp_small" value="{$product.price}" /> /人起
      </dd>
    </dl>

    <dl>
      <dt> 官网地址：</dt>
      <dd>
        <input type="text" name="webUrl" class="inp_default" value="http://www.tripvip.cn/center/product/customdetails/id/{$id}.html" />
      </dd>
    </dl>

    <dl>
      <dt> 官网地址二维码：</dt>
      <dd>
        <img src="http://qr.liantu.com/api.php?bg=f3f3f3&fg=ff0000&gc=222222&el=l&w=200&m=10&text=<php>echo urlencode('http://www.tripvip.cn/center/product/customdetails/id/{$id}.html');</php>" width="100"/>
      </dd>
    </dl>

    <elseif condition="$step eq '1'" />
      <dl>
        <dt> 费用包含 ：</dt>
        <dd>
          <textarea name="costInclude" id="content">{$detail.costInclude}</textarea>
        </dd>
      </dl>
    <elseif condition="$step eq '2'" />
      <dl>
        <dt> 费用不含 ：</dt>
        <dd>
          <textarea name="costNotInclude" id="content">{$detail.costNotInclude}</textarea>
        </dd>
      </dl>
    <elseif condition="$step eq '3'" />
      <dl>
        <dt> 预订须知 ：</dt>
        <dd>
          <textarea name="reservationNotice" id="content">{$detail.reservationNotice}</textarea>
        </dd>
      </dl>
    <elseif condition="$step eq '4'" />
      <dl>
        <dt> 退订须知 ：</dt>
        <dd>
          <textarea name="unreservationNotice" id="content">{$detail.unreservationNotice}</textarea>
        </dd>
      </dl>
    </if>

    <dl>
      <dt> </dt>
      <dd>
        <input type="submit" class="button-green"value="保 存">
        &nbsp;
        <input type="button" onclick="goUrl('{:U('/Home/Product/sell')}')" class="button-return" value="返回产品列表">
      </dd>
    </dl>
  </form>
</div>
<script type="text/javascript">

var price = parseInt("{$product.costPrice}");
/**
 * [changePriceType description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function changePriceType()
{

  var keyCode = event.which;
  if ((keyCode >= 37 && keyCode <=40) || keyCode == 110 || keyCode == 190)
  {
    return;
  }
  else
  {
    var libraryID    = $('input[name="libraryID"]').val();
    var addPriceType = $('select[name="addPriceType"]').val();
    var addPriceNums = $('input[name="addPriceNums"]').val();

    var sellPrice    = '';
    switch (addPriceType)
    {
      case '0':
        sellPrice = Math.ceil(price);
        $('input[name="addPriceNums"]').val('');
        $('input[name="addPriceNums"]').attr('disabled','disabled');
        break;

      case '1':

        if(isNaN(parseInt(addPriceNums)))
        {
          sellPrice = Math.ceil(price);
          $('input[name="addPriceNums"]').val(addPriceNums);
        }
        else
        {

          sellPrice = Math.ceil(parseInt(price) + parseInt(addPriceNums));
          $('input[name="addPriceNums"]').val(parseInt(addPriceNums));
        }

        $('input[name="addPriceNums"]').removeAttr('disabled');
        break;

      case '2':
          if(isNaN(parseInt(addPriceNums)))
          {
            sellPrice = Math.ceil(price);
            $('input[name="addPriceNums"]').val(addPriceNums);
          }
          else
          {

            sellPrice =  Math.ceil(parseInt(price) + (parseInt(price) * parseInt(addPriceNums)*0.01));
            $('input[name="addPriceNums"]').val(parseInt(addPriceNums));
          }

        $('input[name="addPriceNums"]').removeAttr('disabled');
        break;
    }
    $('#priceShow').html(sellPrice);
  }

}

/**
 * [getLibrary description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */

function  getLibrary(obj)
{
  var libraryID = $(obj).val();

   $.ajax({
     url: "/Home/Product/getLibraryAjax",
     type: 'post',
     dataType: 'json',
     data: {'libraryID': libraryID},
     success:function (data) {
       if(data.valid == true)
       {
          $('#departureCitySow').html(data.departureName);
          $('input[name="libraryTitle"]').val(data.libraryTitle);
          $('#priceShow').val(data.price);
          price = data.price;
          changePriceType();
       }
       else
       {
          $('#departureCitySow').empty();
          $('input[name="libraryTitle"]').val('');
          price = parseInt(0);
       }
     }
   })
}

</script>